import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {ServiceLogicService} from '../service/service-logic.service';
import {Admin} from '../domain/admin';
// import * as particlesJS from '../../assets/js/app';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css', './css/reset.css', './css/style.css'],
  encapsulation: ViewEncapsulation.Emulated
})
export class LoginComponent implements OnInit {
  admins: Admin[];
  model = {name: '', password: ''};
  submitted = false;
  active = true;
  onSubmit() {
    this.submitted = true;
    console.log(this.model);
    this.logicService.judgeLogin(this.model.name, this.model.password)
      .then(response => {
        this.admins = response;
        console.log(this.admins);
        if (this.admins.length === 1) {
          switch (this.admins[0].admin_state) {
            case 1:
              this.router.navigate(['/generalStaff', this.admins[0] ]);
              break;
            case 2:
              this.router.navigate(['/executiveStaff', this.admins[0]]);
              break;
            case 3:
              this.router.navigate(['/financeStaff', this.admins[0]]);
              break;
            case 4:
              this.router.navigate(['/deptManager', this.admins[0]]);
              break;
            case 5:
              this.router.navigate(['/viceGeneralManager', this.admins[0]]);
              break;
            case 6:
              this.router.navigate(['/generalManager', this.admins[0]]);
              break;
            case 0:
              this.router.navigate(['/administrate', this.admins[0]]);
              break;
            default:
              break;
          }
        } else {
          alert('用户名或密码错误！'); window.location.reload();
        }
      });
  }
  ngOnInit() {
  }
  constructor(private route: ActivatedRoute, private router: Router, private logicService: ServiceLogicService) {}
}

